﻿using System;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.Collections.Generic;
using System.Xml;

namespace SilverlightTest.Web.Services
{
    [ServiceContract(Namespace = "")]
    [SilverlightFaultBehavior]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class ScoreService
    {
        [OperationContract]
        public Score getScore()
        {
            // Return score value from XML

            Score score = new Score();

            score.playerName = "Diogo";
            score.points = 100;

            return score;
        }

        [OperationContract]
        public List<Score> getHighScores()
        {
            // Return list of all highscores from XML

            //XmlTextReader reader = new XmlTextReader("Scores.xml");

            List<Score> highscores = new List<Score>();

            /*while (reader.Read())
            {
                Score score = new Score();

                if (reader.IsStartElement())
                {
                    switch (reader.Name)
                    {
                        case "playerName":
                            score.playerName = reader.ReadString();
                            break;
                        case "points":
                            score.points = reader.ReadContentAsInt();
                            break;
                    }
                }
            }*/
            
            
            Score score = new Score();
                
            score.playerName = "Diogo";
            score.points = 100;

            highscores.Add(score);



            Score score2 = new Score();

            score2.playerName = "Jon";
            score2.points = 200;

            highscores.Add(score2);

            return highscores;
        }

    
    }

    public class Score
    {
        public string playerName { get; set; }
        public int points { get; set; }
        //date of score
        //time ..
        //level reached
        //lines removed
        //anything else?
        
    }
}
